home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 22 / PCPP #22.iso / Quake2 / q2source_12_11 / utils3 / bsp / qbsp3 / qbsp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-19  |  8.1 KB  |  335 lines

  1.  
  2. #include "cmdlib.h"
  3. #include "mathlib.h"
  4. #include "scriplib.h"
  5. #include "polylib.h"
  6. #include "threads.h"
  7. #include "bspfile.h"
  8.  
  9. #define    MAX_BRUSH_SIDES    128
  10. #define    CLIP_EPSILON    0.1
  11.  
  12. #define    BOGUS_RANGE    8192
  13.  
  14. #define    TEXINFO_NODE        -1        // side is allready on a node
  15.  
  16. typedef struct plane_s
  17. {
  18.     vec3_t    normal;
  19.     vec_t    dist;
  20.     int        type;
  21.     struct plane_s    *hash_chain;
  22. } plane_t;
  23.  
  24. typedef struct
  25. {
  26.     vec_t    shift[2];
  27.     vec_t    rotate;
  28.     vec_t    scale[2];
  29.     char    name[32];
  30.     int        flags;
  31.     int        value;
  32. } brush_texture_t;
  33.  
  34. typedef struct side_s
  35. {
  36.     int            planenum;
  37.     int            texinfo;
  38.     winding_t    *winding;
  39.     struct side_s    *original;    // bspbrush_t sides will reference the mapbrush_t sides
  40.     int            contents;        // from miptex
  41.     int            surf;            // from miptex
  42.     qboolean    visible;        // choose visble planes first
  43.     qboolean    tested;            // this plane allready checked as a split
  44.     qboolean    bevel;            // don't ever use for bsp splitting
  45. } side_t;
  46.  
  47. typedef struct brush_s
  48. {
  49.     int        entitynum;
  50.     int        brushnum;
  51.  
  52.     int        contents;
  53.  
  54.     vec3_t    mins, maxs;
  55.  
  56.     int        numsides;
  57.     side_t    *original_sides;
  58. } mapbrush_t;
  59.  
  60. #define    PLANENUM_LEAF            -1
  61.  
  62. #define    MAXEDGES        20
  63.  
  64. typedef struct face_s
  65. {
  66.     struct face_s    *next;        // on node
  67.  
  68.     // the chain of faces off of a node can be merged or split,
  69.     // but each face_t along the way will remain in the chain
  70.     // until the entire tree is freed
  71.     struct face_s    *merged;    // if set, this face isn't valid anymore
  72.     struct face_s    *split[2];    // if set, this face isn't valid anymore
  73.  
  74.     struct portal_s    *portal;
  75.     int                texinfo;
  76.     int                planenum;
  77.     int                contents;    // faces in different contents can't merge
  78.     int                outputnumber;
  79.     winding_t        *w;
  80.     int                numpoints;
  81.     qboolean        badstartvert;    // tjunctions cannot be fixed without a midpoint vertex
  82.     int                vertexnums[MAXEDGES];
  83. } face_t;
  84.  
  85.  
  86.  
  87. typedef struct bspbrush_s
  88. {
  89.     struct bspbrush_s    *next;
  90.     vec3_t    mins, maxs;
  91.     int        side, testside;        // side of node during construction
  92.     mapbrush_t    *original;
  93.     int        numsides;
  94.     side_t    sides[6];            // variably sized
  95. } bspbrush_t;
  96.  
  97.  
  98.  
  99. #define    MAX_NODE_BRUSHES    8
  100. typedef struct node_s
  101. {
  102.     // both leafs and nodes
  103.     int                planenum;    // -1 = leaf node
  104.     struct node_s    *parent;
  105.     vec3_t            mins, maxs;    // valid after portalization
  106.     bspbrush_t        *volume;    // one for each leaf/node
  107.  
  108.     // nodes only
  109.     qboolean        detail_seperator;    // a detail brush caused the split
  110.     side_t            *side;        // the side that created the node
  111.     struct node_s    *children[2];
  112.     face_t            *faces;
  113.  
  114.     // leafs only
  115.     bspbrush_t        *brushlist;    // fragments of all brushes in this leaf
  116.     int                contents;    // OR of all brush contents
  117.     int                occupied;    // 1 or greater can reach entity
  118.     entity_t        *occupant;    // for leak file testing
  119.     int                cluster;    // for portalfile writing
  120.     int                area;        // for areaportals
  121.     struct portal_s    *portals;    // also on nodes during construction
  122. } node_t;
  123.  
  124. typedef struct portal_s
  125. {
  126.     plane_t        plane;
  127.     node_t        *onnode;        // NULL = outside box
  128.     node_t        *nodes[2];        // [0] = front side of plane
  129.     struct portal_s    *next[2];
  130.     winding_t    *winding;
  131.  
  132.     qboolean    sidefound;        // false if ->side hasn't been checked
  133.     side_t        *side;            // NULL = non-visible
  134.     face_t        *face[2];        // output face in bsp file
  135. } portal_t;
  136.  
  137. typedef struct
  138. {
  139.     node_t        *headnode;
  140.     node_t        outside_node;
  141.     vec3_t        mins, maxs;
  142. } tree_t;
  143.  
  144. extern    int            entity_num;
  145.  
  146. extern    plane_t        mapplanes[MAX_MAP_PLANES];
  147. extern    int            nummapplanes;
  148.  
  149. extern    int            nummapbrushes;
  150. extern    mapbrush_t    mapbrushes[MAX_MAP_BRUSHES];
  151.  
  152. extern    vec3_t        map_mins, map_maxs;
  153.  
  154. #define    MAX_MAP_SIDES        (MAX_MAP_BRUSHES*6)
  155.  
  156. extern    int            nummapbrushsides;
  157. extern    side_t        brushsides[MAX_MAP_SIDES];
  158.  
  159. extern    qboolean    noprune;
  160. extern    qboolean    nodetail;
  161. extern    qboolean    fulldetail;
  162. extern    qboolean    nomerge;
  163. extern    qboolean    nosubdiv;
  164. extern    qboolean    nowater;
  165. extern    qboolean    noweld;
  166. extern    qboolean    noshare;
  167. extern    qboolean    notjunc;
  168.  
  169. extern    vec_t        microvolume;
  170.  
  171. extern    char        outbase[32];
  172.  
  173. extern    char    source[1024];
  174.  
  175. void     LoadMapFile (char *filename);
  176. int        FindFloatPlane (vec3_t normal, vec_t dist);
  177.  
  178. //=============================================================================
  179.  
  180. // textures.c
  181.  
  182. typedef struct
  183. {
  184.     char    name[64];
  185.     int        flags;
  186.     int        value;
  187.     int        contents;
  188.     char    animname[64];
  189. } textureref_t;
  190.  
  191. #define    MAX_MAP_TEXTURES    1024
  192.  
  193. extern    textureref_t    textureref[MAX_MAP_TEXTURES];
  194.  
  195. int    FindMiptex (char *name);
  196.  
  197. int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin);
  198.  
  199. //=============================================================================
  200.  
  201. void FindGCD (int *v);
  202.  
  203. mapbrush_t *Brush_LoadEntity (entity_t *ent);
  204. int    PlaneTypeForNormal (vec3_t normal);
  205. qboolean MakeBrushPlanes (mapbrush_t *b);
  206. int        FindIntPlane (int *inormal, int *iorigin);
  207. void    CreateBrush (int brushnum);
  208.  
  209.  
  210. //=============================================================================
  211.  
  212. // draw.c
  213.  
  214. extern vec3_t    draw_mins, draw_maxs;
  215. extern    qboolean    drawflag;
  216.  
  217. void Draw_ClearWindow (void);
  218. void DrawWinding (winding_t *w);
  219.  
  220. void GLS_BeginScene (void);
  221. void GLS_Winding (winding_t *w, int code);
  222. void GLS_EndScene (void);
  223.  
  224. //=============================================================================
  225.  
  226. // csg
  227.  
  228. bspbrush_t *MakeBspBrushList (int startbrush, int endbrush,
  229.         vec3_t clipmins, vec3_t clipmaxs);
  230. bspbrush_t *ChopBrushes (bspbrush_t *head);
  231. bspbrush_t *InitialBrushList (bspbrush_t *list);
  232. bspbrush_t *OptimizedBrushList (bspbrush_t *list);
  233.  
  234. void WriteBrushMap (char *name, bspbrush_t *list);
  235.  
  236. //=============================================================================
  237.  
  238. // brushbsp
  239.  
  240. void WriteBrushList (char *name, bspbrush_t *brush, qboolean onlyvis);
  241.  
  242. bspbrush_t *CopyBrush (bspbrush_t *brush);
  243.  
  244. void SplitBrush (bspbrush_t *brush, int planenum,
  245.     bspbrush_t **front, bspbrush_t **back);
  246.  
  247. tree_t *AllocTree (void);
  248. node_t *AllocNode (void);
  249. bspbrush_t *AllocBrush (int numsides);
  250. int    CountBrushList (bspbrush_t *brushes);
  251. void FreeBrush (bspbrush_t *brushes);
  252. vec_t BrushVolume (bspbrush_t *brush);
  253.  
  254. void BoundBrush (bspbrush_t *brush);
  255. void FreeBrushList (bspbrush_t *brushes);
  256.  
  257. tree_t *BrushBSP (bspbrush_t *brushlist, vec3_t mins, vec3_t maxs);
  258.  
  259. //=============================================================================
  260.  
  261. // portals.c
  262.  
  263. int VisibleContents (int contents);
  264.  
  265. void MakeHeadnodePortals (tree_t *tree);
  266. void MakeNodePortal (node_t *node);
  267. void SplitNodePortals (node_t *node);
  268.  
  269. qboolean    Portal_VisFlood (portal_t *p);
  270.  
  271. qboolean FloodEntities (tree_t *tree);
  272. void FillOutside (node_t *headnode);
  273. void FloodAreas (tree_t *tree);
  274. void MarkVisibleSides (tree_t *tree, int start, int end);
  275. void FreePortal (portal_t *p);
  276. void EmitAreaPortals (node_t *headnode);
  277.  
  278. void MakeTreePortals (tree_t *tree);
  279.  
  280. //=============================================================================
  281.  
  282. // glfile.c
  283.  
  284. void OutputWinding (winding_t *w, FILE *glview);
  285. void WriteGLView (tree_t *tree, char *source);
  286.  
  287. //=============================================================================
  288.  
  289. // leakfile.c
  290.  
  291. void LeakFile (tree_t *tree);
  292.  
  293. //=============================================================================
  294.  
  295. // prtfile.c
  296.  
  297. void WritePortalFile (tree_t *tree);
  298.  
  299. //=============================================================================
  300.  
  301. // writebsp.c
  302.  
  303. void SetModelNumbers (void);
  304. void SetLightStyles (void);
  305.  
  306. void BeginBSPFile (void);
  307. void WriteBSP (node_t *headnode);
  308. void EndBSPFile (void);
  309. void BeginModel (void);
  310. void EndModel (void);
  311.  
  312. //=============================================================================
  313.  
  314. // faces.c
  315.  
  316. void MakeFaces (node_t *headnode);
  317. void FixTjuncs (node_t *headnode);
  318. int GetEdge2 (int v1, int v2,  face_t *f);
  319.  
  320. face_t    *AllocFace (void);
  321. void FreeFace (face_t *f);
  322.  
  323. void MergeNodeFaces (node_t *node);
  324.  
  325. //=============================================================================
  326.  
  327. // tree.c
  328.  
  329. void FreeTree (tree_t *tree);
  330. void FreeTree_r (node_t *node);
  331. void PrintTree_r (node_t *node, int depth);
  332. void FreeTreePortals_r (node_t *node);
  333. void PruneNodes_r (node_t *node);
  334. void PruneNodes (node_t *node);
  335.